<template>
  <section>
    <el-dialog
      title="重置密码"
      :visible.sync="visible"
      :value="value"
      width="500px"
    >
      <el-form
        :model="reset"
        :rules="$rules.user"
        ref="resetForm"
      >
        <el-form-item
          label="用户密码"
          :label-width="labelWidth"
          prop="pwd"
        >
          <el-input
            v-model="reset.pwd"
            auto-complete="off"
            type="password"
            suffix-icon="fa fa-eye"
            placeholder="请输入密码"
          />
        </el-form-item>
        <el-form-item
          label="确认密码"
          :label-width="labelWidth"
          prop="rePwd"
        >
          <el-input
            v-model="reset.rePwd"
            auto-complete="off"
            type="password"
            suffix-icon="fa fa-eye"
            placeholder="请再次输入密码"
          />
        </el-form-item>
      </el-form>
      <span
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="cancle">取 消</el-button>
        <el-button
          type="primary"
          @click="submit"
        >确 定</el-button>
      </span>
    </el-dialog>
  </section>
</template>

<style>
</style>

<script>
export default {
  name: "ResetPassword",
  data() {
    return {
      visible: false,
      labelWidth: "",
      reset: {
        id: 0,
        pwd: ""
      }
    };
  },
  watch: {
    value: {
      deep: true,
      immediate: true,
      handler: function(val) {
        this.visible = val.show;
        this.labelWidth = val.formLabelWidth || "120px";
        this.reset.id = val.id;
      }
    },
    visible(val) {
      if (!val) this.$emit("on-show-change", this.$data);
    }
  },
  methods: {
    cancle() {
      this.visible = false;
      this.reset = {
          id: 0,
          pwd: "",
          rePwd: ""
      };
    },
    submit() {
      /*this.$api.user.reset(this.reset, () => {
        this.$message({
          type: "success",
          message: "重置成功",
          onClose: this.cancle
        });
      });*/
    }
  },
  props: {
    value: {
      type: Object,
      default: function() {
        return {
          show: false,
          formLabelWidth: "120px",
          id: 0
        };
      }
    }
  }
};
</script>
